package com.qf.qflivehou.controller;

import com.qf.qflivehou.pojo.reqVo.ShopCartReq;
import com.qf.qflivehou.pojo.respVo.ResponseData;
import com.qf.qflivehou.service.ShopCartService;
import org.apache.catalina.servlet4preview.http.HttpServletRequest;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author Mr.Liu
 * @date 2022/1/12 17:15
 */
@RestController
@RequestMapping("/shop")
public class ShopCartController {

    @Resource
    private ShopCartService shopCartService;

    /**
     * 添加购物车
     * @param shopCartReq
     * @return
     */
    @PostMapping("/addShopCart")
    public ResponseData addShopCart(@RequestBody ShopCartReq shopCartReq, HttpServletRequest request){
        ResponseData responseData = shopCartService.addShopCart(shopCartReq,request);
        return responseData;
    }

    /**
     * 通过token获取用户得购物车信息
     * @param request
     * @return
     */
    @PostMapping("/findShopCartByToken")
    public ResponseData findShopCartByToken(HttpServletRequest request){
        ResponseData responseData  = shopCartService.findShopCartByToken(request);
        return responseData;
    }

    /**
     * 删除购物车
     * @param shopCartReq
     * @return
     */
    @RequestMapping("/delShop")
    public ResponseData delShop(@RequestBody ShopCartReq shopCartReq,HttpServletRequest request){
        ResponseData responseData = shopCartService.delShop(shopCartReq,request);
        return responseData;
    }
}
